// 监听来自content script的消息
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
    if (request.action === 'showData') {
        // 存储数据到storage
        chrome.storage.local.set({ scrapedData: request.data }, () => {
            // 打开popup显示数据
            chrome.action.openPopup();
        });
    } else if (request.action === 'downloadImage') {
        // 下载图片
        chrome.downloads.download({
            url: request.imageUrl,
            filename: request.fileName,
            saveAs: false
        }, () => {
            // 通知content script下载已开始
            sendResponse();
        });
        // 返回true表示我们会异步调用sendResponse
        return true;
    }
}); 